package managedbean.SCM.Batch;

import javaclass.ProductType;
import java.io.Serializable;
import java.util.Date;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import session.stateless.SCM.BatchBeanLocal;

@ManagedBean(name = "addProductBatchManagerBean")
@ViewScoped
public class AddProductBatchManagerBean implements Serializable{

    public AddProductBatchManagerBean() {
    }
    
    @EJB
    private BatchBeanLocal batchBeanLocal;
    private ProductType productType;
    private Date expiryDate;
    private Long quantity;
    private String location;
    private String statusMessage;

    public Date getExpiryDate() {
        return expiryDate;
    }

    public void setExpiryDate(Date expiryDate) {
        this.expiryDate = expiryDate;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public ProductType getProductType() {
        return productType;
    }

    public void setProductType(ProductType productType) {
        this.productType = productType;
    }

    public Long getQuantity() {
        return quantity;
    }

    public void setQuantity(Long quantity) {
        this.quantity = quantity;
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }
    
    public void saveNewProductBatch(ActionEvent event) {
        
        try 
        {
            System.out.println(location);
            System.out.println(productType);
            System.out.println(expiryDate);
            System.out.println(quantity);
            
            Long id = batchBeanLocal.createProductBatch(productType, expiryDate, quantity, location);
            
            if(id == null){
                statusMessage = "Please Try Again.";
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Unsuccessful:" + statusMessage + "", ""));
            }else{
                statusMessage = "New Product Batch " + id + " Saved Successfully.";
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, statusMessage, ""));
            }
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
    }
    
}
